package com.yjd.merchant.api.setting;

import com.yjd.comm.base.control.MerchantBaseControl;
import com.yjd.comm.merchant.dto.MerchantLimitSetDto;
import com.yjd.comm.org.service.IOrganizationService;
import com.yjd.comm.project.model.ProjectRateConfig;
import com.yjd.comm.project.service.IProjectService;
import com.yjd.comm.util.FrameUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 *  商户端自助设置业务参数
 * Created by yjd-wap on 2017/10/23.
 */

@Controller
@Scope("prototype")
@RequestMapping("/setting/")
public class MerchantSettingControl extends MerchantBaseControl {


    /**
     * 配置机构贷款期限
     * @param limitSetDto
     * @throws Exception
     */
    @RequestMapping(value = "limit", method = RequestMethod.POST)
    public void limit(MerchantLimitSetDto limitSetDto) throws Exception {
        if (limitSetDto == null || limitSetDto.getLimitList() == null) {
            FrameUtil.throwBaseException1("请求参数不能为空");
        }
        organizationService.updateOrgLimit(super.getMerchantId(), limitSetDto.getLimitList());
        this.successMsg("项目期限配置成功");
    }

    /**
     * 项目上架
     * @param project_id
     * @throws Exception
     */
    @RequestMapping(value = "project/open", method = RequestMethod.POST)
    public void projectOpen(Long project_id) throws Exception {
        if (project_id == null) {
            FrameUtil.throwBaseException1("请求参数不能为空");
        }
        projectService.openProject(super.getMerchantId(),project_id);
        this.successMsg("项目上架成功");
    }

    /**
     * 项目下架
     * @param project_id
     * @throws Exception
     */
    @RequestMapping(value = "project/close", method = RequestMethod.POST)
    public void projectClose(Long project_id) throws Exception {
        if (project_id == null) {
            FrameUtil.throwBaseException1("请求参数不能为空");
        }
        projectService.colseProject(super.getMerchantId(),project_id);
        this.successMsg("项目下架成功");
    }

    /**
     * 商户修改价格
     * @param project_id
     * @throws Exception
     */
    @RequestMapping(value = "project/price/info", method = RequestMethod.POST)
    public void projectPriceInfo(Long project_id,Double project_price,Double act_price,Double payment,ProjectRateConfig projectRateConfig) throws Exception {
        if (project_id == null||project_price==null||act_price==null||payment==null||projectRateConfig==null) {
            FrameUtil.throwBaseException1("请求参数不能为空");
        }
        projectService.updateProjectPrice(super.getMerchantId(),project_id,project_price,act_price,payment,projectRateConfig);
        this.successMsg("项目价格修改成功");
    }

    /**
     * 商户项目利率配置
     * @param project_id
     * @throws Exception
     */
    @RequestMapping(value = "project/rateConfig", method = RequestMethod.POST)
    public void projectRateConfig(Long project_id, ProjectRateConfig projectRateConfig) throws Exception {
        if (project_id == null||projectRateConfig==null) {
            FrameUtil.throwBaseException1("请求参数不能为空");
        }
        projectService.updateProjecRate(super.getMerchantId(),project_id,projectRateConfig);
        this.successMsg("商户利率修改成功");
    }

    @Resource
    private IOrganizationService organizationService;

    @Resource
    private IProjectService projectService;
}
